﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using RMS.Models;
using System.Web.UI.HtmlControls;
using System.Web.Routing;

namespace RMS
{
    public partial class PageTemplate : System.Web.UI.MasterPage
    {
      
        protected void Page_Load(object sender, EventArgs e) {
            // Page Refreshes on load.  (fix for Internet Explorer)
            //Response.AddHeader("Expires", "0");
            btnLogout.Visible = false;
        
        }

        protected void generateBannerButtons()
        {
            if (Session["IsAdmin"] != null) {

                if ((bool)Session["IsAdmin"] == true)
                {
                    Response.Write("<form><input type=\"button\" class=\"myButton\" value=\"View Account\" onClick=\"window.location.href='/admin/retreats'\"></form>");
                    btnLogout.Visible = true;                
                }
                else
                {
                    Response.Write("<form><input type=\"button\" class=\"myButton\" value=\"View Account\" onClick=\"window.location.href='/Pages/UserAccount.aspx'\"></form>");
                    btnLogout.Visible = true; 
                }
            }
            else {

                if (Session["ID"] == null)
                {
                    Response.Write("<form><input type=\"button\" class=\"myButton\" value=\"Login\" onClick=\"window.location.href='/Pages/Login.aspx'\"></form>");
                    btnLogout.Visible = false; 
                }
                else
                {
                    Response.Write("<form><input type=\"button\" class=\"myButton\" value=\"View Account\" onClick=\"window.location.href='/Pages/UserAccount.aspx'\"></form>");
                    btnLogout.Visible = true; 
                }
           }
        }

      
        public void btnLogout_Click(object sender, EventArgs e)
        {
            Session["IsAdmin"] = null;
            Session["ID"] = null;
            Session["Name"] = null;
            Session["Email"] = null;
            Session["Password"] = null;
            Session.Clear();            
            Response.AddHeader("Expires", "0");
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.Redirect("~/Pages/Login.aspx");
            Response.Redirect(Request.RawUrl);
        }
           
    }
}